Avoid chaining up to parent impl, since we have a INPUT_ONLY window.
authorOwen Taylor <otaylor@redhat.com>
Mon, 2 Apr 2001 20:15:18 +0000 (20:15 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Mon, 2 Apr 2001 20:15:18 +0000 (20:15 +0000)
Mon Apr  2 16:13:58 2001  Owen Taylor  <otaylor@redhat.com>

* gtk/gtkinvisible.c (gtk_invisible_style_set): Avoid
chaining up to parent impl, since we have a INPUT_ONLY
window.

* gtk/gtkentry.[ch]: Add a cursor_color property to set the
foreground color for the cursor.

gtk/gtkentry.c
gtk/gtkentry.h
gtk/gtkinvisible.c

index 1d1a36e4cbcb5c0ef3a4571a32640215a528a0db..d620f389df72318c20e465405bee25386b7062d7 100644 (file)
@@ -425,7 +425,14 @@ gtk_entry_class_init (GtkEntryClass *class)
                                                      
                                                      -1,
                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
-  
+
+  gtk_widget_class_install_style_property (widget_class,
+                                          g_param_spec_boxed ("cursor_color",
+                                                              _("Cursor color"),
+                                                              _("Color with which to draw insertion cursor"),
+                                                              GTK_TYPE_GDK_COLOR,
+                                                              G_PARAM_READABLE));
+
   signals[INSERT_TEXT] =
     gtk_signal_new ("insert_text",
                    GTK_RUN_LAST,
@@ -824,6 +831,24 @@ gtk_entry_finalize (GObject *object)
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static void
+gtk_entry_realize_cursor_gc (GtkEntry *entry)
+{
+  GdkColor *cursor_color;
+  
+  if (entry->cursor_gc)
+    gdk_gc_unref (entry->cursor_gc);
+
+  gtk_widget_style_get (GTK_WIDGET (entry), "cursor_color", &cursor_color, NULL);
+  if (cursor_color)
+    {
+      entry->cursor_gc = gdk_gc_new (entry->text_area);
+      gdk_gc_set_rgb_fg_color (entry->cursor_gc, cursor_color);
+    }
+  else
+    entry->cursor_gc = gdk_gc_ref (GTK_WIDGET (entry)->style->bg_gc[GTK_STATE_SELECTED]);
+}
+
 static void
 gtk_entry_realize (GtkWidget *widget)
 {
@@ -883,9 +908,11 @@ gtk_entry_realize (GtkWidget *widget)
   gdk_window_set_user_data (entry->text_area, entry);
 
   gdk_cursor_destroy (attributes.cursor);
-  
+
   widget->style = gtk_style_attach (widget->style, widget->window);
 
+  gtk_entry_realize_cursor_gc (entry);
+
   gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
   gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
 
@@ -915,8 +942,17 @@ gtk_entry_unrealize (GtkWidget *widget)
       entry->text_area = NULL;
     }
 
+  if (entry->cursor_gc)
+    {
+      gdk_gc_unref (entry->cursor_gc);
+      entry->cursor_gc = NULL;
+    }
+
   if (entry->popup_menu)
-    gtk_widget_destroy (entry->popup_menu);
+    {
+      gtk_widget_destroy (entry->popup_menu);
+      entry->popup_menu = NULL;
+    }
 
   if (GTK_WIDGET_CLASS (parent_class)->unrealize)
     (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
@@ -1653,6 +1689,8 @@ gtk_entry_style_set       (GtkWidget      *widget,
 
       gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
       gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
+
+      gtk_entry_realize_cursor_gc (entry);
     }
 }
 
@@ -2373,7 +2411,7 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
       
       gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
       
-      gdk_draw_line (entry->text_area, widget->style->bg_gc[GTK_STATE_SELECTED], 
+      gdk_draw_line (entry->text_area, entry->cursor_gc,
                     xoffset + strong_x, INNER_BORDER,
                     xoffset + strong_x, text_area_height - INNER_BORDER);
       
index f94072b98e0977fa8d987d91a6682f163da2dc44..a35e2be3cdaef633613bb061c74efb4f4b0aa974 100644 (file)
@@ -102,6 +102,8 @@ struct _GtkEntry
   gunichar invisible_char;
 
   gint width_chars;
+
+  GdkGC *cursor_gc;
 };
 
 struct _GtkEntryClass
index 2594c3b7d42ebb003a3bff7c62ac1774e4fbd630..8757fe42a4dfac7ecb584c59a3c8903bae61a37b 100644 (file)
 #include "gtksignal.h"
 #include "gtkinvisible.h"
 
-static void gtk_invisible_class_init               (GtkInvisibleClass *klass);
-static void gtk_invisible_init                     (GtkInvisible      *invisible);
-static void gtk_invisible_destroy                  (GtkObject        *object);
-static void gtk_invisible_realize                  (GtkWidget        *widget);
-static void gtk_invisible_show                     (GtkWidget        *widget);
-static void gtk_invisible_size_allocate            (GtkWidget        *widget,
-                                                   GtkAllocation    *allocation);
+static void gtk_invisible_class_init    (GtkInvisibleClass *klass);
+static void gtk_invisible_init          (GtkInvisible      *invisible);
+static void gtk_invisible_destroy       (GtkObject         *object);
+static void gtk_invisible_realize       (GtkWidget         *widget);
+static void gtk_invisible_style_set     (GtkWidget         *widget,
+                                        GtkStyle          *previous_style);
+static void gtk_invisible_show          (GtkWidget         *widget);
+static void gtk_invisible_size_allocate (GtkWidget         *widget,
+                                        GtkAllocation     *allocation);
 
 GtkType
 gtk_invisible_get_type (void)
@@ -71,6 +73,7 @@ gtk_invisible_class_init (GtkInvisibleClass *class)
   object_class = (GtkObjectClass*) class;
 
   widget_class->realize = gtk_invisible_realize;
+  widget_class->style_set = gtk_invisible_style_set;
   widget_class->show = gtk_invisible_show;
   widget_class->size_allocate = gtk_invisible_size_allocate;
 
@@ -138,6 +141,13 @@ gtk_invisible_realize (GtkWidget *widget)
   widget->style = gtk_style_attach (widget->style, widget->window);
 }
 
+static void
+gtk_invisible_style_set (GtkWidget *widget,
+                        GtkStyle  *previous_style)
+{
+  /* Don't chain up to parent implementation */
+}
+
 static void
 gtk_invisible_show (GtkWidget *widget)
 {